<?
	require_once("../cBasic/950cons.php");

	$output=array();

	$sQuery= "select * from contract";
	$rResult = mysql_query( $sQuery, $con ) or die(mysql_error());
	while ( $aRow = mysql_fetch_array( $rResult ) )
	{
		$rec=array();
		$rec[]=$aRow['ContID'];
		$rec[]=$aRow['ReqID'];
		$rec[]=$aRow['EmpID'];
		$rec[]=$aRow['SkillID'];
		$rec[]='$ '.$aRow['Payment'].'.00 / Hour';
		$rec[]=$aRow['ConRegDate'];
		$output['contract'][]=$rec;
	}
	for ($i=0;$i<count($output['contract']);$i++){
		$sQuery= "select * from request where ReqID = '".$output['contract'][$i][1]."'";
		$rResult = mysql_query( $sQuery, $con ) or die(mysql_error());
		$rec=array();
		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$rec[]=$aRow['StartDate'];
			$rec[]=$aRow['EndDate'];
			$output['request'][]=$rec;
		}
		
		$sQuery= "select * from employee where EmpID = '".$output['contract'][$i][2]."'";
		$rResult = mysql_query( $sQuery, $con ) or die(mysql_error());
		$rec=array();
		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$rec[]=$aRow['EmpFName'];
			$rec[]=$aRow['EmpLName'];
			$output['employee'][]=$rec;
		}
		
		$sQuery= "select * from skill where skID = '".$output['contract'][$i][3]."'";
		$rResult = mysql_query( $sQuery, $con ) or die(mysql_error());
		$rec=array();
		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$rec[]=$aRow['skCode'];
			$output['skill'][]=$rec;
		}
	}
	
	mysql_close($con);
	
	$outputs=array();
	for ($i=0;$i<count($output['contract']);$i++){
		$recs=array();
		$recs[]=$output['contract'][$i][0];
		$recs[]=$output['request'][$i][0];
		$recs[]=$output['request'][$i][1];
		$recs[]=$output['employee'][$i][0];
		$recs[]=$output['employee'][$i][1];
		$recs[]=$output['skill'][$i][0];
		$recs[]=$output['contract'][$i][4];
		$recs[]=$output['contract'][$i][5];
		$outputs[]=$recs;
	}
	
	echo json_encode($outputs);
?>